{extend name="table"}

{block name="button"}
<!--{if auth("add")}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-table-id="LevelTable" data-modal="{:url('add')}">{:lang('添加等级')}</button>
<!--{/if}-->
{/block}

{block name="content"}
<div class="think-box-shadow">
    {include file='base/level/index_search'}
    <table id="LevelTable" data-url="{:request()->url()}" data-target-search="form.form-search"></table>
</div>
{/block}

{block name='script'}
<script>

    $(function () {
        let $table = $('#LevelTable').layTable({
            even: true, height: 'full',
            sort: {field: 'number', type: 'asc'},
            cols: [[
                {field: 'number', title: '{:lang("序号")}', align: "center", minWidth: 70, width: '5%', sort: true},
                {field: 'cover', title: '{:lang("图标")}', width: 70, align: 'center', templet: '<div>{{-$.layTable.showImage(d.cover)}}</div>'},
                {field: 'name', title: '{:lang("等级名称")}', align: 'center', minWidth: 80, width: '12%'},
                {
                    title: '{:lang("团队计数")}', align: 'center', minWidth: 80, templet: function (d) {
                        return d.upgrade_team ? '<b class="layui-icon layui-icon-ok-circle color-green"></b>' : '-';
                    }
                },
                {
                    title: '{:lang("升级规则")}', align: 'center', minWidth: 80, templet: function (d) {
                        return d.upgrade_type === 1 ? '<span class="color-green">' + '{:lang("全部条件")}' + '</span>' : '<span class="color-blue">' + '{:lang("任意条件")}' + '</span>';
                    }
                },
                {
                    title: '{:lang("入会礼包")}', align: 'center', minWidth: 80, templet: function (d) {
                        return d.extra.enter_vip_status ? '<b class="layui-icon layui-icon-ok-circle color-green"></b>' : '-';
                    }
                },

                {
                    title: '{:lang("订单金额")}', align: 'center', minWidth: 80, templet: function (d) {
                        return d.extra.order_amount_status ? laytpl('<b>{{d.extra.order_amount_number}}</b>').render(d) : '-';
                    }
                },
                {field: 'status', title: '{:lang("等级状态")}', align: 'center', minWidth: 110, width: '8%', templet: '#StatusSwitchTpl'},
                // {field: 'create_time', title: '{:lang("创建时间")}', align: 'center', minWidth: 170, width: '15%', sort: true},
                {toolbar: '#toolbar', title: '{:lang("操作面板")}', align: 'center', minWidth: 150, fixed: 'right'},
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            let data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('state')}", data, 'post', function (ret) {
                let fn = () => $table.trigger('reload');
                ret.code > 0 ? fn() : $.msg.error(ret.info, 3, fn)
                return false;
            }, false);
        });
    });

</script>

<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('已激活')}|{:lang('已禁用')}" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">' + '{:lang("已启用")}' + '</b>' : '<b class="color-red">' + '{:lang("已禁用")}' + '</b>'}}
    <!--{/if}-->
</script>

<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">
    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-table-id="LevelTable" data-title="{:lang('编辑等级')}" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
    <!--{/if}-->

    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-danger layui-btn-sm" data-confirm="{:lang('确定要删除等级吗?')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    <!--{/if}-->
</script>
{/block}